﻿using JinJun.YShowReception.Core;
using JinJun.YShowReception.JobScheduler.Common;
using JinJun.YShowReception.JobScheduler.Job;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace JinJun.YShowReception.WinService
{
    public partial class Service1 : ServiceBase
    {
        private readonly string trigroup = "servicetrigroup";
        private readonly string trigGroupName = "servicetrigGroupName";

        public Service1()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 服务启动
        /// </summary>
        /// <param name="args"></param>
        protected async override void OnStart(string[] args)
        {
            //实例化调度程序
            ISchedulerFactory sf = new StdSchedulerFactory();
            IScheduler _sched = await sf.GetScheduler();
            List<string> list = ConfigurationHelper.GetSectionKeyList("Crons");
            if (list.Contains(JobType.logJob))
            {
                JobSchedulerManager.AddScheduler<LogJob>(ref _sched, JobType.logJob, trigroup, trigGroupName);
            }
            if (list.Contains(JobType.backupJob))
            {
                JobSchedulerManager.AddScheduler<BackupJob>(ref _sched, JobType.backupJob, trigroup, trigGroupName);
            }
            if (list.Contains(JobType.emailJob))
            {
                JobSchedulerManager.AddScheduler<EmailJob>(ref _sched, JobType.emailJob, trigroup, trigGroupName);
            }
            await _sched.Start();
        }


        /// <summary>
        ///服务停止
        /// </summary>
        protected override void OnStop()
        {

        }
    }
}
